package com.frxuexi.visit

import androidx.lifecycle.MutableLiveData
import com.frxuexi.lib_base.entity.VisitBean
import com.frxuexi.lib_base.entity.VisitBeanItem
import com.frxuexi.lib_base.mvvm.BaseViewModel
import com.frxuexi.lib_base.net.ApiService
import com.frxuexi.lib_base.net.VideoApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class VisitViewModel @Inject constructor(val apiService: ApiService):BaseViewModel(){
    val visitsData = MutableLiveData<VisitBean>()
    val visitsByIdData = MutableLiveData<VisitBeanItem>()
    val addVisitsData = MutableLiveData<VisitBeanItem>()

    val approveVisitsData = MutableLiveData<VisitBeanItem>()

    fun getVisits(){
        httpRequest({apiService.getVisits()},visitsData::postValue)
    }

    fun getVisitByStatus(status:String){
        httpRequest({apiService.getVisitByStatus(status)},visitsData::postValue)
    }

    fun getVisitByName(name:String){
        httpRequest({apiService.getVisitByName(name)},visitsData::postValue)
    }

    fun getVisitById(id:Int){
        httpRequest({apiService.getVisitById(id)},visitsByIdData::postValue)
    }

    fun addVisit(item: VisitBeanItem){
        httpRequest({apiService.addVisit(toBody(item))},addVisitsData::postValue)
    }

    fun approveVisit(id: Int){
        httpRequest({apiService.approveVisit(id)},approveVisitsData::postValue)
    }

    fun rejectVisit(id: Int){
        httpRequest({apiService.rejectVisit(id)},approveVisitsData::postValue)
    }


}